//
// Created by jeff on 2025/8/17.
//

#include <iostream>
#include <vector>
#include <chrono>
#include <functional>

using namespace std;
using namespace std::chrono;

struct ValueView {
    int v;
    ValueView(int x) : v(x) {}
};

using VectorFunc = function<int(const vector<ValueView>&)>;
using VariadicFunc = function<int(ValueView, ValueView, ValueView, ValueView)>; // 例子：4 参数

int vector_sum(const vector<ValueView>& args) {
    int sum = 0;
    for (auto& a : args) sum += a.v;
    return sum;
}

int variadic_sum(ValueView a, ValueView b, ValueView c, ValueView d) {
    return a.v + b.v + c.v + d.v;
}

template<typename F>
long long bench(F&& f, int N) {
    auto start = high_resolution_clock::now();
    volatile int result = 0;
    for (int i = 0; i < N; i++) {
        result += f();
    }
    auto end = high_resolution_clock::now();
    return duration_cast<milliseconds>(end - start).count();
}

int main() {
    int N = 100000000; // 1e8 次调用
    vector<ValueView> args = {1, 2, 3, 4};

    auto t1 = bench([&]() { return vector_sum(args); }, N);
    auto t2 = bench([&]() { return variadic_sum(args[0], args[1], args[2], args[3]); }, N);

    cout << "vector call:   " << t1 << " ms" << endl;
    cout << "variadic call: " << t2 << " ms" << endl;

    return 0;
}
